﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Skipper_Connector
{
    public partial class FinderWindows : Form
    {
        public FinderWindows()
        {
            InitializeComponent();
            ShowList();
        }
        private void ShowList()
        {
            if (!Directory.Exists(Config.DataPath))
                return;
            joblist.Items.Clear();
            foreach (var mdb in Directory.GetFiles(Config.DataPath, "*.mdb"))
            {
                FileInfo fi = new FileInfo(mdb);
                if (fi.Name.ToLower().Contains(keywordsBox.Text.ToLower()))
                    joblist.Items.Add(fi.Name);
            }
        }

        private void keywordsBox_TextChanged(object sender, EventArgs e)
        {
            ShowList();
        }

        private void ShowParts(List<CombinedPart> parts)
        {
            PartsGridView.DataSource = parts;

            PartsGridView.Columns["PartName"].HeaderText = "板件名称";
            PartsGridView.Columns["Qty"].HeaderText = "数量";
            PartsGridView.Columns["Length"].HeaderText = "板长";
            PartsGridView.Columns["Width"].HeaderText = "板宽";
            PartsGridView.Columns["Thickness"].HeaderText = "厚度";
            PartsGridView.Columns["Material"].HeaderText = "材料名称";
            PartsGridView.Columns["PartsIndex"].HeaderText = "板序";
            PartsGridView.Columns["ProductsIndex"].HeaderText = "产品号";
            PartsGridView.Columns["Barcode"].HeaderText = "条码";
        }

        private void joblist_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (joblist.SelectedItem != null)
                ShowParts(BusinessHelper.Report(joblist.SelectedItem.ToString()));
        }

    }
}
